@extends('admin::layouts.master')
@section('title')
    订单列表
@endsection
@section('tab')

		<div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form" >
                	{{csrf_field()}}
                    <!-- <input type="hidden" value="" name="shop_ids"> -->
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>优惠券名称</label>
                        <div class="layui-input-inline">
                            <input type="text" id="username" placeholder="请输入优惠券名称" name="name" required="" lay-verify="required" autocomplete="off" class="layui-input"></div>
                    </div>

                    <div class="layui-form-item" id="type_use" hidden>
                        <label class="layui-form-label"><span class="x-red">*</span>使用类型</label>
                        <div class="layui-input-inline">
                            <select name="type" required="">
                                <option value="1">普通商品</option>
                                <option value="2">服务商品</option>
                                <option value="3">保养套餐</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>补贴比例(%)</label>
                        <div class="layui-input-inline">
                            <input type="number" id="username" min="1" max="100" placeholder="请输入补贴比例" name="subsidy" required="" lay-verify="required" autocomplete="off" class="layui-input"></div>
                    </div>


                    <div class="layui-inline">
                        <label class="layui-form-label"><span class="x-red">*</span>优惠券类型</label>
                        <div class="layui-input-inline">
                        <select  lay-filter="coupon_type" name="pid" required="">
                            <option value="">请选择优惠券类型</option>
                            @foreach( $coupons_types as $key=>$vo )
                                <option value="{{$key}}">{{$vo}}</option>
                            @endforeach
                        </select>
                        </div>
                    </div>

                    <div class="layui-form-item" id="mj_price" hidden>
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>减(元)</label>
                        <div class="layui-input-inline">
                            <input type="number" id="username" min="0.01" placeholder="请输入优惠金额" name="price" autocomplete="off" class="layui-input"></div>
                    </div>

                    <div class="layui-form-item" id="zk_price" hidden>
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>折</label>
                        <div class="layui-input-inline">
                            <input type="number" id="username" min="1" max="10" maxlength="2" placeholder="请输入折扣数量（1~10）"  name="discount_num" autocomplete="off" class="layui-input"></div>
                    </div>

                    <div class="layui-form-item" id="min_price" hidden>
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>满(元)</label>
                        <div class="layui-input-inline">
                            <input type="number" id="username" min="1" placeholder="请输入最低消费金额" name="price_all" autocomplete="off" class="layui-input"></div>
                    </div>

                    <div class="layui-form-item" id="xc_price" hidden>
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>面值(元)</label>
                        <div class="layui-input-inline">
                            <input type="number" id="username" min="1" max="99" maxlength="2" placeholder="请输入面值金额"  name="price_all2" autocomplete="off" class="layui-input"></div>
                    </div>

                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>优惠券说明</label>
                        <div class="layui-input-inline">
                            <textarea placeholder="请输入优惠券说明"  lay-verify="required" name="content" class="layui-textarea" style="width: 400px; height: 100px;"></textarea>    
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>有效期(天)</label>
                        <div class="layui-input-inline">
                            <input type="number" id="username" min="1" placeholder="领取优惠券后有效期（天）" name="validity_at" required="" lay-verify="required" autocomplete="off" class="layui-input"></div>
                    </div>

			        <div class="layui-form-item">
			            <label for="L_repass" class="layui-form-label"></label>
			            <button class="layui-btn" lay-filter="add" lay-submit="">添加</button>
			        </div>
        		</form>
        	</div>
        </div>

@endsection

@section('tab_js')
    <script>
        layui.use(['form', 'layer', 'jquery','tree','util'], function () {
            $ = layui.jquery;
            var form = layui.form,
                // tree = layui.tree,
                // util = layui.util,
                layer = layui.layer;
               // var type ='';
               // var goods_id =[];

                // //指定商品使用优惠券
                // tree.render({
                //     elem: '#check_shop'
                //     ,data: data2
                //     ,showCheckbox: true //是否开启多选框
                //     ,showLine: false  //是否开启连接线
                //     ,oncheck: function(obj){
                //         if( obj.checked ){  //选中
                //             if( obj.data.children == undefined ){   //只选择了子类
                //                 goods_id.push(obj.data.id);
                //             }else{    //选中父类【全选】
                //                 $.each( obj.data.children , function( index , el ){
                //                     goods_id.push(el.id);
                //                 })    
                //             }
                //         }else{  //取消选中
                //             if( obj.data.children == undefined ){   //只取消了子类
                //                 goods_id.splice($.inArray(obj.data.id ,goods_id),1);
                //             }else{      //取消了父类【取消全选】
                //                 goods_id =[];
                //             }
                //         }
                //         $("input[name='shop_ids']").val( goods_id );
                //     }
                // });

            


                var is_submit = false;
            //监听提交
            form.on('submit(add)', function (data) {
                if( is_submit ){
                    return false;
                }
                is_submit = true;
                $.ajax({
                    url: js_url('admin-coupon-store'),
                    type: 'post',
                    data: data.field,
                    dataType: "json",
                    success: function (result) {
                        if (result.state === 0) {
                            layer.msg(result.msg, {time: 1000, icon: 6}, function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                        } else {
                            is_submit = false;
                            layer.msg(result.msg, {time: 2000, icon: 5});
                        }
                    }
                });
                return false;
            });

            form.on('select(coupon_type)',function(data){
                if( data.value == 1 ){
                    $("#mj_price").hide();
                    $("#zk_price").hide();
                    $("#min_price").hide();
                    $("#type_use").hide();
                    $("#xc_price").show();
                }else if( data.value == 2 ){
                    $("#mj_price").show();
                    $("#zk_price").hide();
                    $("#min_price").show();
                    $("#type_use").show();
                    $("#xc_price").hide();
                }else if( data.value == 3 ){
                    $("#mj_price").hide();
                    $("#zk_price").show();
                    $("#min_price").show();
                    $("#type_use").show();
                    $("#xc_price").hide();
                }else{
                    $("#mj_price").hide();
                    $("#zk_price").hide();
                    $("#min_price").hide();
                    $("#type_use").show();
                    $("#xc_price").hide();

                }
            });

            //限制条件选择
            // form.on('select(type)',function(data){
            //    type = data.value;
            //    if( type == 2 ){ //指定商品
            //         $.ajax({
            //         url: js_url('admin-coupon-store'),
            //         type: 'post',
            //         data: data.field,
            //         dataType: "json",
            //         success: function (result) {
            //             if (result.state === 0) {
                           
            //             } else {
            //                 layer.msg(result.msg, {time: 2000, icon: 5});
            //             }
            //         }
            //     });
            //    }
            // });
        });



          //模拟数据2
  // var data2 = [{
  //   title: '早餐'
  //   ,id: 1
  //   ,children: [{
  //     title: '油条'
  //     ,id: 5
  //   },{
  //     title: '包子'
  //     ,id: 6
  //   },{
  //     title: '豆浆'
  //     ,id: 7
  //   }]
  // }];


    </script>
@endsection